Skip to content

feat(bazaar): add MCP resource type support to Go SDK#1967

Open
avidreder wants to merge 6 commits intox402-foundation:mainfrom
avidreder:feat/golang-bazaar-mcp
Open

feat(bazaar): add MCP resource type support to Go SDK#1967
avidreder wants to merge 6 commits intox402-foundation:mainfrom
avidreder:feat/golang-bazaar-mcp

Conversation

@avidreder
Copy link
Copy Markdown
Contributor

Summary

  • Add MCP tool discovery extension types (McpInput, McpTransport, McpDiscoveryInfo, DeclareMcpDiscoveryConfig) to the shared types package and re-export from bazaar
  • Add DeclareMcpDiscoveryExtension() for servers to declare MCP tool resources with tool name, input schema, transport, description, and example
  • Update DiscoveryInfo.UnmarshalJSON to discriminate type: "mcp" from HTTP inputs, enabling correct JSON round-trips
  • Add MCP bypass in EnrichDeclaration() so MCP extensions pass through without HTTP method narrowing or dynamic route extraction
  • Extend DiscoveredResource with ToolName field and update both ExtractDiscoveredResourceFromPaymentPayload and ExtractDiscoveredResourceFromPaymentRequired to handle MCP extraction
  • Achieves parity with the TypeScript and Python SDKs for MCP bazaar resource support

Test plan

  • All existing HTTP bazaar tests pass (no regressions)
  • TestDeclareMcpDiscoveryExtension — full config, minimal config, missing toolName/inputSchema errors, transport variants
  • TestValidateDiscoveryExtension_MCP — schema validation passes for MCP extensions
  • TestDiscoveryInfoUnmarshalJSON_MCP — JSON round-trip correctly produces McpInput
  • TestExtractDiscoveredResourceFromPaymentPayload_MCP — v2 MCP extension in PaymentPayload extracts ToolName
  • TestExtractDiscoveredResourceFromPaymentRequired_MCP — v2 MCP in PaymentRequired
  • TestBazaarResourceServerExtension_MCP — EnrichDeclaration passes MCP through unchanged (including with dynamic route context)
  • TestExtractDiscoveryInfoFromExtension_MCP — direct extraction from MCP extension
  • Full SDK test suite: go test ./... passes

🤖 Generated with Claude Code

Add MCP tool discovery extensions to the bazaar package, achieving
parity with the TypeScript and Python SDKs. Servers can now declare
MCP tool discovery extensions alongside HTTP resources, and facilitators
can detect and extract them from payment payloads.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added go sdk Changes to core v2 packages labels Apr 8, 2026
avidreder and others added 4 commits April 8, 2026 14:46
Co-Authored-By: Claude <noreply@anthropic.com>
…e tests

- Fix transport schema enum to include both valid values (streamable-http,
  sse) instead of only the provided value, matching TypeScript SDK behavior
- Fix doc.go examples to use bazaar.BAZAAR.Key() instead of bazaar.BAZAAR
- Inline createMcpDiscoveryExtension into DeclareMcpDiscoveryExtension
- Add negative validation tests for wrong type and empty toolName
- Add edge case tests for whitespace-only toolName and invalid transport

Co-Authored-By: Claude <noreply@anthropic.com>
Add Extensions field to PaymentWrapperConfig and pass it through to the
PaymentRequired struct in 402 responses. This brings the MCP payment
wrapper to parity with the HTTP middleware's RouteConfig.Extensions
support, enabling bazaar discovery extensions in MCP tool responses.

- Add Extensions map to PaymentWrapperConfig (types.go)
- Set extensions in paymentRequiredResult (server.go)
- Add unit tests for extensions present/absent in 402 (server_test.go)
- Declare bazaar MCP extension in E2E server (main.go)
- Add bazaar extension integration test (mcp_evm_test.go)

Co-Authored-By: Claude <noreply@anthropic.com>
Add extensions support to the TS MCP PaymentWrapperConfig and pass it
through to createPaymentRequiredResponse so bazaar discovery metadata
appears in 402 responses. Wire the E2E server with declareDiscoveryExtension
for the get_weather tool. Add Go mocked-transport integration tests
(5 cases) covering the full client↔server payment flow to match TS
mcp-payment-flow.test.ts coverage.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
// Example: map[string]interface{}{"city": "San Francisco"},
// })
func DeclareMcpDiscoveryExtension(config types.DeclareMcpDiscoveryConfig) (types.DiscoveryExtension, error) {
if config.ToolName == "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: strings.TrimSpace(config.ToolName) == "" to avoid whitespace strings

expect(err.paymentRequired).toBeDefined();
// Verify bazaar extension is present if the server was configured with it
// This test validates extension passthrough from server to client
if (err.paymentRequired?.extensions?.bazaar) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test is called should include bazaar extensions in 402 response however this check bypasses the asserts if the extension is not present


// Current implementation only checks for empty string, so whitespace passes declaration.
// This documents the current behavior.
require.NoError(t, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test says should return error when toolName is whitespace-only, but the actual assert is for success, because prior to this whitespace was being let through

require.True(t, ok)
assert.Equal(t, bazaar.McpTransport("custom-protocol"), mcpInput.Transport)

// But schema validation should fail because transport enum only allows known values
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we want the schema validation to fail if transport is a value that isn't in the enum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants